<div class="row">
    <div class="col-md-12 widget-module">
        <div class="box-widget">
            <div class="widget-head clearfix">
                <h4 class="pull-left"><?php echo $this->translate('create price'); ?></h4>
            </div>
            
            <div class="widget-container">
                <div class="widget-block">
                    <div class="widget-content">
                        <form id="usergroup" method="post" class="form-horizontal form-box">
                            <div class="form-group">
                                <label class="col-lg-4 control-label" style="text-align: left;"><?php echo $this->translate('product name'); ?></label>
                                <label class="col-lg-1 control-label" style="text-align: left;"><?php echo $this->translate('net'); ?></label>
                                <label class="col-lg-1 control-label" style="text-align: left;"><?php echo $this->translate('brand'); ?></label>
                                <label class="col-lg-2 control-label" style="text-align: left;"><?php echo $this->translate('price'); ?></label>
                                <label class="col-lg-2 control-label" style="text-align: left;"><?php echo $this->translate('discount value'); ?></label>
                                <label class="col-lg-2 control-label" style="text-align: left;"><?php echo $this->translate('discount type'); ?></label>
                            </div>
                            <?php foreach($this->products as $product): ?>
                            <div class="form-group <?php echo $this->classError[$product['id']]; ?>">
                                <label class="col-lg-4 control-label" style="text-align: left; text-transform: capitalize;"><?php echo $product['name']; ?></label>
                                <label class="col-lg-1 control-label" style="text-align: left;"><?php echo $product['net']; ?>g</label>
                                <label class="col-lg-1 control-label" style="text-align: left; text-transform: uppercase;"><?php echo $product['brand']; ?></label>
                                <div id="price" class="col-lg-2">
                                    <?php
                                        if(isset($product['price'])){
                                            $price = $product['price'];
                                        }else{
                                            $price = $product['p_price'];
                                        }
                                        
                                        if(isset($product['discount_value'])){
                                            $discount = $product['discount_value'];
                                        }else{
                                            $discount = 0;
                                        }
                                    ?>
                                    <input id="price" class="form-control" type="text" value="<?php echo $price; ?>" class="form-control" id="price" />
                                    <input type="hidden" value="<?php echo $price; ?>" name="price[<?php echo $product['id']; ?>]" />
                                </div>
                                
                                <div class="col-lg-2">
                                    <input class="form-control" type="text" value="<?php echo $discount; ?>" name="discount[<?php echo $product['id']; ?>]" class="form-control" id="price" />
                                </div>
                                
                                <div class="col-lg-2">
                                    <select class="form-control" name="discount_type[<?php echo $product['id']; ?>]">
                                        <option <?php if(isset($product['discount_type']) && $product['discount_type'] == 0) echo 'selected="selected"'; ?> value="0"><?php echo $this->translate('fixed'); ?></option>
                                        <option <?php if(isset($product['discount_type']) && $product['discount_type'] == 1) echo 'selected="selected"'; ?> value="1"><?php echo $this->translate('percent'); ?></option>
                                    </select>
                                </div>
                                <?php echo $this->messageError[$product['id']]['price']; ?>
                                <?php echo $this->messageError[$product['id']]['discount']; ?>
                            </div>
                            <?php endforeach; ?>
                            
                            <div class="form-group">
                                <label class="col-lg-4 control-label">&nbsp;</label>
                                <div class="col-lg-4">
                                    <div class="form-actions">
                                        <button type="submit" class="btn btn-primary">
                                            <i class="icon-save"></i>
                                            <?php echo $this->translate('save'); ?>
                                        </button>
                                        <button id="cancel" type="button" class="btn">
                                            <i class="icon-cancel-circle-2"></i>
                                            <?php echo $this->translate('cancel'); ?>
                                        </button>
                                    </div>
                                </div>
                            </div> 
                            <input type="hidden" name="customer_id" value="<?php echo $this->customer_id; ?>" />
                            <input type="hidden" name="save" value="1" />
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
$("#cancel").click(function(){
    window.location = "<?php echo $this->url(array('module' => 'admin', 'controller' => 'product-price', 'action' => 'index'), null, true); ?>";
});

$(document).ready(function(){
    $("#price").focus();
    
    var optionNumeric = {'aSep': '.', 'aDec': ',', 'mDec': 0, 'wEmpty': 'zero', 'vMin': 0, 'vMax': 999999999999};
    $("input#price").autoNumeric('init', optionNumeric);
    $("input#price").change(function(){
        var value = $(this).autoNumeric('get');
        
        $(this).parent("div#price").children("input[name^='price']").val(value);
    });
});
</script>